
//Transfers pokemon that are loaded
PM_FUNC_NORM_ATTRIB PokemonTransfer( Int:player1, Int:pokeNum1, Int:player2, Int:pokeNum2 )
{
	pokemod_funcstart_debug( "PokemonTransfer" );

	//Temporarily store information about both pokemon slots
	// player1 stores into 0
	// player2 stores into 1
	new String:szPokeName[ 2 ][ NAME_LEN ];
	copy( szPokeName[ 0 ], charsmax(szPokeName[]), g_szPlayerPokemonNames[ player1 ][ pokeNum1 ] );
	copy( szPokeName[ 1 ], charsmax(szPokeName[]), g_szPlayerPokemonNames[ player2 ][ pokeNum2 ] );

	new String:szOwnerName[ 2 ][ NAME_LEN ];
	copy( szOwnerName[ 0 ], charsmax(szOwnerName[]), g_iPlayerPokemonOwner[ player1 ][ pokeNum1 ] );
	copy( szOwnerName[ 1 ], charsmax(szOwnerName[]), g_iPlayerPokemonOwner[ player2 ][ pokeNum2 ] );

	new Int:pokemonStats[ 2 ][ PM_POKESTAT ];
	for ( new PM_POKESTAT:i; i < PM_POKESTAT; i++ )
	{
		pokemonStats[ 0 ][ i ] = g_iPlayerPokemonStats[ player1 ][ pokeNum1 ][ i ];
		pokemonStats[ 1 ][ i ] = g_iPlayerPokemonStats[ player2 ][ pokeNum2 ][ i ];
	}

	new POKESKILL:pokemonSkills[ 2 ][ SKILLS_PER_POKEMON ];
	new Int:skillPPs[ 2 ][ SKILLS_PER_POKEMON ];
	for ( new Int:i; i < SKILLS_PER_POKEMON; i++ )
	{
		pokemonSkills[ 0 ][ i ] = g_iPlayerPokemonSkills[ player1 ][ pokeNum1 ][ i ];
		pokemonSkills[ 1 ][ i ] = g_iPlayerPokemonSkills[ player2 ][ pokeNum2 ][ i ];
		skillPPs[ 0 ][ i ] = g_iPlayerSkillPP[ player1 ][ pokeNum1 ][ i ];
		skillPPs[ 1 ][ i ] = g_iPlayerSkillPP[ player2 ][ pokeNum2 ][ i ];
	}

	//Change the information for each slot to the other slot
	// player1 gets info from 1
	// player2 gets info from 0
	copy( g_szPlayerPokemonNames[ player1 ][ pokeNum1 ], charsmax( g_szPlayerPokemonNames[][] ), szPokeName[ 1 ] );
	copy( g_szPlayerPokemonNames[ player2 ][ pokeNum2 ], charsmax( g_szPlayerPokemonNames[][] ), szPokeName[ 0 ] );

	copy( g_iPlayerPokemonOwner[ player1 ][ pokeNum1 ], charsmax( g_szPlayerPokemonNames[][] ), szOwnerName[ 1 ] );
	copy( g_iPlayerPokemonOwner[ player2 ][ pokeNum2 ], charsmax( g_szPlayerPokemonNames[][] ), szOwnerName[ 0 ] );

	for ( new PM_POKESTAT:i; i < PM_POKESTAT; i++ )
	{
		g_iPlayerPokemonStats[ player1 ][ pokeNum1 ][ i ] = pokemonStats[ 1 ][ i ];
		g_iPlayerPokemonStats[ player2 ][ pokeNum2 ][ i ] = pokemonStats[ 0 ][ i ];
	}

	for ( new Int:i; i < SKILLS_PER_POKEMON; i++ )
	{
		g_iPlayerPokemonSkills[ player1 ][ pokeNum1 ][ i ] = pokemonSkills[ 1 ][ i ];
		g_iPlayerPokemonSkills[ player2 ][ pokeNum2 ][ i ] = pokemonSkills[ 0 ][ i ];
		g_iPlayerSkillPP[ player1 ][ pokeNum1 ][ i ] = skillPPs[ 1 ][ i ];
		g_iPlayerSkillPP[ player2 ][ pokeNum2 ][ i ] = skillPPs[ 0 ][ i ];
	}

	//Save both slots now
	// player1 saves info from 1
	// player2 saves info from 0
	new String:szSaveName[ NAME_LEN ];
	SaveNameSlot( szSaveName, charsmax(szSaveName), pokeNum1 );
	SavePlayerPokemon( player1, .szSave = szSaveName,
							.szPokeName = szPokeName[ 1 ],
							.iPokemonStats = pokemonStats[ 1 ],
							.iPokemonSkills = pokemonSkills[ 1 ],
							.iSkillPPs = skillPPs[ 1 ],
							.szOwnerName = szOwnerName[ 1 ]
	);

	SaveNameSlot( szSaveName, charsmax(szSaveName), pokeNum2 );
	SavePlayerPokemon( player2, .szSave = szSaveName,
							.szPokeName = szPokeName[ 0 ],
							.iPokemonStats = pokemonStats[ 0 ],
							.iPokemonSkills = pokemonSkills[ 0 ],
							.iSkillPPs = skillPPs[ 0 ],
							.szOwnerName = szOwnerName[ 0 ]
	);

	pokemod_funcend_debug( "PokemonTransfer" );
}

//Can switch pokemon in and out of PC
PM_FUNC_NORM_ATTRIB PokemonSwitch( Int:id, Int:pokeNum, String:szLoad[] )
{
	pokemod_funcstart_debug( "PokemonSwitch" );

	new String:szPokeSlot[ NAME_LEN ];
	SaveNameSlot( szPokeSlot, charsmax(szPokeSlot), pokeNum );

	player_switch_keys( id, szPokeSlot, szLoad );

	LoadPlayerPokemon( id, pokeNum );

	pokemod_funcend_debug( "PokemonSwitch" );
}

PM_FUNC_NORM_ATTRIB PokemonInitSkills( Int:pokeID, Int:iLevel, POKESKILL:pokemonSkills[ SKILLS_PER_POKEMON ] )
{
	pokemod_funcstart_debug( "PokemonInitSkills" );

	for ( new Int:iSkillNum; iSkillNum < SKILLS_PER_POKEMON; iSkillNum++ )
	{
		pokemonSkills[ iSkillNum ] = SKILL_INVALID;
	}

	new Int:fileHandle = fopen( FileName( FILE_POKEMON ), "rt" );

	new Int:iTell, Int:iAssumedTell = ArrayGetCell( g_iPokemonTells, pokeID );

	if ( !FileSeekToName( fileHandle, PokeToName( pokeID ), iAssumedTell, iTell ) )
	{
		pokemod_funcend_debug( "PokemonInitSkills Poke Not Found" );
		return;
	}

	if ( iAssumedTell != iTell )
		ArraySetCell( g_iPokemonTells, pokeID, iTell );

	new String:szData[ 128 ];
	new POKESKILL:iSkillID, bool:bSkillLearned, Int:iSkillNum;

	new Int:iDataStart;

	while ( !feof( fileHandle ) )
	{
		fgets( fileHandle, szData, charsmax(szData) );
		trim( szData );

		if ( szData[ 0 ] == '#' )
			break;

		if ( szData[ 0 ] == ';' || ( szData[ 0 ] == '/' && szData[ 1 ] == '/' ) )
			continue;

		iDataStart = -1;

		if ( equali( szData, "Init", 4 ) )
		{
			iDataStart = 4;
		}
		else if ( equali( szData, "LevelUp(", 8 ) )
		{
			trim( szData[ 8 ] );
			if ( str_to_num( szData[ 8 ] ) <= iLevel )
				iDataStart = 8;
		}

		if ( iDataStart != -1 )
		{
			iDataStart = containi( szData, "LearnSkill(" );
			if ( iDataStart == -1 )
				continue;

			//Move to the end of LearnSkill(
			iDataStart += 11;

			trim( szData[ iDataStart ] );
			iSkillID = NameToSkill( szData[ iDataStart ] );
			if ( iSkillID == SKILL_INVALID )
			{
				pokemod_debug( "Invalid Init Skill ('%s') for %s", szData[ iDataStart ], PokeToName( pokeID ) );
				continue;
			}

			bSkillLearned = false;

			for ( iSkillNum = 0; iSkillNum < SKILLS_PER_POKEMON; iSkillNum++ )
			{
				if ( pokemonSkills[ iSkillNum ] == SKILL_INVALID )
				{
					pokemonSkills[ iSkillNum ] = iSkillID;
					bSkillLearned = true;
					break;
				}
			}

			if ( !bSkillLearned && random( 3 ) )
			{
				pokemonSkills[ random( SKILLS_PER_POKEMON ) ] = iSkillID;
			}
		}
	}
	fclose( fileHandle );

	pokemod_funcend_debug( "PokemonInitSkills" );
}

PM_FUNC_NORM_ATTRIB PokemonInfo( Int:pokeID, String:szInfo[], String:szCopy[] = "", Int:copyLen = 0 )
{
	new String:szData[ 64 ];
	if ( pokeID <= -1 )
		return szData;

	new Int:iAssumedTell = ArrayGetCell( g_iPokemonTells, pokeID );
	nfv_get_data( FileName( FILE_POKEMON ), PokeToName( pokeID ), szInfo, szData, charsmax(szData), '#', .key_tell_start = iAssumedTell );

	if ( copyLen )
		copy( szCopy, copyLen, szData );

	return szData;
}

PM_FUNC_NORM_ATTRIB PM_TYPE:PokemonType( Int:pokeID )
{
	new String:szData[ 64 ], String:szLeft[ 32 ];
	PokemonInfo( pokeID, "Type", szData, charsmax(szData) );

	new PM_TYPE:tempType, PM_TYPE:finalType;
	while ( ValidData( szData ) )
	{
		strbreak( szData, szLeft, charsmax(szLeft), szData, charsmax(szData) );

		tempType = NameToType( szLeft );
		if ( tempType > TYPE_NONE )
			finalType |= tempType;
	}

	return finalType;
}

PM_FUNC_NORM_ATTRIB PokemonMaxHP( Int:iPokeID, Int:iLevel, Int:iPokeIVs, Int:iPokeEV = 0 )
{
	new Int:iPokeIV = StatSingleIV( iPokeIVs, POKESTAT_HP_EV );
	return StatCalculate( POKESTAT_HP_EV, iPokeID, iLevel, iPokeEV, iPokeIV );
}

PM_FUNC_NORM_ATTRIB PokemonGiveDamage( Int:id )
{
	new Int:encounterID = PlayerGetInfo( id, PINFO_ENCOUNTER_POKEMON );
	new Int:iWiggles = PlayerGetInfo( id, PINFO_ENCOUNTER_WIGGLES );
	if ( encounterID <= 0 || iWiggles )
		return;

	pokemod_funcstart_debug( "PokemonGiveDamage" );

	new Int:iPokeNum = PlayerGetInfo( id, PINFO_ACTIVE_POKENUM );
	new Int:iLevel = g_iPlayerPokemonStats[ id ][ iPokeNum ][ POKESTAT_LEVEL ];

	new Int:encounterHP = PlayerGetInfo( id, PINFO_ENCOUNTER_HP );
	new Int:encounterLevel = PlayerGetInfo( id, PINFO_ENCOUNTER_LEVEL );
	new Int:encounterIVs = PlayerGetInfo( id, PINFO_ENCOUNTER_IVS );
	new Int:encounterMaxHP = PokemonMaxHP( encounterID, encounterLevel, encounterIVs );

	new Float:fLevelPercent = float( iLevel ) / float( encounterLevel );
	new Int:iDamage = floatround( encounterMaxHP * fLevelPercent / 10.0, floatround_ceil );

	encounterHP -= iDamage;

	//if the encountered pokemon died
	if ( encounterHP < 0 )
	{
		//xpAmount = ( BaseXP * level * wild(1 or 1.5 for wild) ) / 7

		new Int:iBaseXP = str_to_num( PokemonInfo( encounterID, "BaseEXP" ) );
		new Int:iXPAmount = floatround( ( iBaseXP * encounterLevel * 1.5 ) / 7.0 );
		PlayerGiveXP( id, iPokeNum, iXPAmount );

		new String:szPokeName[ NAME_LEN ];
		PokeToName( encounterID, szPokeName, charsmax(szPokeName) );

		encounterHP = 0;
		DHudEventMessage( id, "Enemy %s has fainted.", szPokeName );
		StatAddYield( id, iPokeNum, encounterID );

		LocationScript( .iPlayer = id, .iLocation = PlayerGetInfo( id, PINFO_LOCATION ), .szForward = "Defeat", .szArgument = szPokeName );

		PlayerSetInfo( id, PINFO_ENCOUNTER_POKEMON, 0 );
	}
	else if ( PlayerGetInfo( id, PINFO_SETTING_AUTOCATCH ) )
	{
		//if the encountered pokemon has less than 15% hp left
		if ( encounterHP <= ( ( encounterMaxHP * 15 ) / 100 ) )
		{
			EncounterAttemptCatch( id, encounterID, encounterHP, encounterMaxHP, .iItemUsed = -1 );
		}
	}

	PlayerSetInfo( id, PINFO_ENCOUNTER_HP, encounterHP );

	pokemod_funcend_debug( "PokemonGiveDamage" );
}

PM_FUNC_NORM_ATTRIB PokemonTakeDamage( Int:id, Int:iPokeNum, Int:iDamage )
{
	new Int:encounterID = PlayerGetInfo( id, PINFO_ENCOUNTER_POKEMON );
	new Int:iWiggles = PlayerGetInfo( id, PINFO_ENCOUNTER_WIGGLES );
	if ( encounterID <= 0 || iWiggles )
		return;

	new Int:pokeHP = g_iPlayerPokemonStats[ id ][ iPokeNum ][ POKESTAT_HP ];
	if ( pokeHP <= 0 )
		return;

	pokemod_funcstart_debug( "PokemonTakeDamage" );

	new Int:level = g_iPlayerPokemonStats[ id ][ iPokeNum ][ POKESTAT_LEVEL ];
	pokeHP -= ( ( iDamage * level ) / ( g_iMaxLevel ) ); 

	g_iPlayerPokemonStats[ id ][ iPokeNum ][ POKESTAT_HP ] = max( 0, pokeHP );
	SavePlayerPokeStat( id, iPokeNum, POKESTAT_HP );

	if ( pokeHP <= 0 )
	{
		//if the player didn't change pokemon
		if ( !PokemonFainted( id, iPokeNum ) )
		{
			PlayerSetInfo( id, PINFO_ENCOUNTER_POKEMON, 0 );
//			DHudEventMessage( id, "Enemy %s ran away.", PokeToName( encounterID ) );
		}
	}

	pokemod_funcend_debug( "PokemonTakeDamage" );
}

PM_FUNC_NORM_ATTRIB PokemonFainted( Int:id, Int:pokeNum )
{
	for ( new Int:iPokeNum; iPokeNum < POKEMON_PER_PLAYER; iPokeNum++ )
	{
		if ( pokeNum == iPokeNum )
			continue;
		if ( PlayerChangePokemon( id, iPokeNum, .bForced = true ) )
			return true;
	}

	//if the player didn't change pokemon
	if ( PlayerGetInfo( id, PINFO_ACTIVE_POKENUM ) == pokeNum && g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_POKEMON ] )
	{
		new Int:iTeleportLocation = PlayerGetInfo( id, PINFO_LAST_POKECENTER );
		if ( iTeleportLocation == g_iLocationGlobal )
			iTeleportLocation = NameToLocation( SettingGetValue( START_LOCATION ) );

		PlayerSetInfo( id, PINFO_LOCATION, iTeleportLocation );
		PlayerSetInfo( id, PINFO_TRAVELING, 0 );
		PokemonHeal( id, -1, -1, .bRevive = true );
		DHudEventMessage( id, "All your pokemon have fainted.^n You were awakened at %s.", LocationToName( iTeleportLocation ) );
		return false;
	}

	return true;
}

PM_FUNC_NORM_ATTRIB PokemonGiveItem( Int:id, Int:pokeNum, Int:iItemID, String:szExtraScript[ 128 ] )
{
	pokemod_funcstart_debug( "PokemonGiveItem" );

	if ( pokeNum == -1 )
	{
		new Int:menu = MenuCreate( "Give %s to which pokemon?", ItemToName( iItemID ) );

		new String:szData[ 128 ];

		new Int:iActiveNum = PlayerGetInfo( id, PINFO_ACTIVE_POKENUM );

		new Int:cPrefix;
		new Int:pokeID, Int:pokeIVs, Int:pokeEV;
		new Int:iLevel, Int:iHP, Int:iMaxHP, String:szHP[ 16 ];
		for ( pokeNum = 0; pokeNum < POKEMON_PER_PLAYER; pokeNum++ )
		{
			pokeID = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_POKEMON ];
			if ( pokeID <= 0 )
				continue;

			cPrefix = ( iActiveNum == pokeNum ) ? 'y' : 'w';

			pokeIVs = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_IVS ];
			pokeEV = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP_EV ];

			iLevel = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_LEVEL ];
			iHP = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP ];
			iMaxHP = PokemonMaxHP( pokeID, iLevel, pokeIVs, pokeEV );

			if ( iHP <= 0 )
			{
				cPrefix = 'd';
				copy( szHP, charsmax(szHP), "Fainted" );
			}
			else
			{
				formatex( szHP, charsmax(szHP), "HP:%d/%d", iHP, iMaxHP );
			}

			formatex( szData, charsmax(szData), "g%d %d %s", iItemID, pokeNum, szExtraScript );
			MenuAddItem( menu, szData, "\%c%32s Lvl:%d %s", cPrefix, PokeNumToName( pokeNum, .playerID = id ), iLevel, szHP );
		}

		MenuExit( id, menu, .bExitOption = false );
		formatex( szData, charsmax(szData), "g%d -1", iItemID );
		MenuAddItem( menu, szData, "Cancel" );

		MenuDisplay( id, menu, MENU_USE_ITEM );
	}
	else
	{
		new Int:pokeID = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_POKEMON ];

		g_iScriptPokeNum = pokeNum;
		g_iScriptItem = iItemID;

		FileScript( id, FileName( FILE_POKEMON ), PokeToName( pokeID ), "GiveItem", ItemToName( iItemID ), ArrayGetCell( g_iPokemonTells, pokeID ) );

		FileScript( id, FileName( FILE_ITEMS ), ItemToName( iItemID ), "ItemGiven", "", ArrayGetCell( g_iItemTells, iItemID ) );

		ScriptDoLine( id, szExtraScript );

		g_iScriptItem = -1;
		g_iScriptPokeNum = -1;
	}

	pokemod_funcend_debug( "PokemonGiveItem" );
}

PM_FUNC_NORM_ATTRIB PokemonHeal( Int:id, Int:pokeNum, Int:iHealAmount, bool:bRevive )
{
	new Int:pokeID, Int:level, Int:pokeIVs, Int:pokeHPEV, Int:iMaxHP, Int:iCurrentHP;
	if ( pokeNum == -1 )
	{
		new Int:iHeals;
		for ( pokeNum = 0; pokeNum < POKEMON_PER_PLAYER; pokeNum++ )
		{
			pokeID = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_POKEMON ];
			if ( pokeID <= 0 )
				continue;

			level = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_LEVEL ];
			pokeIVs = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_IVS ];
			pokeHPEV = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP_EV ];
			iCurrentHP = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP ];
			iMaxHP = PokemonMaxHP( pokeID, level, pokeIVs, pokeHPEV );
			if ( ( !bRevive && !iCurrentHP ) || iCurrentHP >= iMaxHP )
				continue;

			if ( iHealAmount == -1 )
			{
				g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP ] = iMaxHP;
			}
			else
			{
				g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP ] = clamp( iCurrentHP + iHealAmount, 0, iMaxHP );
			}

			SavePlayerPokeStat( id, pokeNum, POKESTAT_HP );

			iHeals++;
		}
		return iHeals;
	}
	else
	{
		pokeID = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_POKEMON ];
		if ( pokeID <= 0 )
			return 0;

		level = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_LEVEL ];
		pokeIVs = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_IVS ];
		pokeHPEV = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP_EV ];
		iCurrentHP = g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP ];
		iMaxHP = PokemonMaxHP( pokeID, level, pokeIVs, pokeHPEV );
		if ( ( !bRevive && !iCurrentHP ) || iCurrentHP >= iMaxHP )
			return 0;

		if ( iHealAmount == -1 )
		{
			g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP ] = iMaxHP;
		}
		else
		{
			g_iPlayerPokemonStats[ id ][ pokeNum ][ POKESTAT_HP ] = clamp( iCurrentHP + iHealAmount, 0, iMaxHP );
		}

		SavePlayerPokeStat( id, pokeNum, POKESTAT_HP );
	}
	return 1;
}

PM_FUNC_NORM_ATTRIB PokemonResetPP( Int:id, Int:iPokeNum )
{
	new Int:iSkillNum, POKESKILL:iSkillID;
	if ( iPokeNum == -1 )
	{
		for ( iPokeNum = 0; iPokeNum < POKEMON_PER_PLAYER; iPokeNum++ )
		{
			if ( !g_iPlayerPokemonStats[ id ][ iPokeNum ][ POKESTAT_POKEMON ] )
				continue;

			for ( iSkillNum = 0; iSkillNum < SKILLS_PER_POKEMON; iSkillNum++ )
			{
				iSkillID = g_iPlayerPokemonSkills[ id ][ iPokeNum ][ iSkillNum ]
				if ( iSkillID == SKILL_INVALID )
					continue;

				g_iPlayerSkillPP[ id ][ iPokeNum ][ iSkillNum ] = SkillInfo( iSkillID, SI_PP );
			}
		}
	}
	else
	{
		for ( iSkillNum = 0; iSkillNum < SKILLS_PER_POKEMON; iSkillNum++ )
		{
			iSkillID = g_iPlayerPokemonSkills[ id ][ iPokeNum ][ iSkillNum ]
			if ( iSkillID == SKILL_INVALID )
				continue;

			g_iPlayerSkillPP[ id ][ iPokeNum ][ iSkillNum ] = SkillInfo( iSkillID, SI_PP );
		}
	}
	return true;
}

PM_FUNC_NORM_ATTRIB PokemonShowInfo( Int:iViewer, Int:iOwner, Int:iPokeNum )
{
	pokemod_funcstart_debug( "PokemonShowInfo" );

	new String:szTitle[ 64 ];
	formatex( szTitle, charsmax(szTitle), "%s - %s", PlayerToName( iOwner ), PokeNumToName( iPokeNum, .playerID = iOwner ) );

	new String:szMOTD[2048], Int:iLen;

	iLen += copy( szMOTD[iLen], charsmax(szMOTD)-iLen, "<center><b>Pokemon<br><table border=^"1^"><tr><td><center>" );

	new Int:iPokeID = g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ POKESTAT_POKEMON ];

	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "<img src=^"%s^" height=^"120^"><br>", PokemonInfo( iPokeID, "ImageL" ) );
	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "<b>%s</b><br>", PokeNumToName( iPokeNum, .playerID = iOwner ) );
	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "Type: %s<br>", PokemonInfo( iPokeID, "Type" ) );
	iLen += copy( szMOTD[iLen], charsmax(szMOTD)-iLen, "<table border=^"1^"><tr><td>" );

	new POKESKILL:iPokeSkill;
	for ( new Int:iSkillNum; iSkillNum < SKILLS_PER_POKEMON; iSkillNum++ )
	{
		iPokeSkill = g_iPlayerPokemonSkills[ iOwner ][ iPokeNum ][ iSkillNum ];
		if ( iPokeSkill > SKILL_INVALID )
		{
			iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "%s - %s<br>", SkillToName( iPokeSkill ), SkillGetHelp( iPokeSkill ) );
		}
	}

	iLen += copy( szMOTD[iLen], charsmax(szMOTD)-iLen, "</td><td>" );

	new Int:iLevel = g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ POKESTAT_LEVEL ];
	new Int:iPokeIVs = g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ POKESTAT_IVS ];
	new Int:iPokeEV = g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ POKESTAT_HP_EV ];
	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "HP: %d/%d<br>", g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ POKESTAT_HP ], PokemonMaxHP( iPokeID, iLevel, iPokeIVs, iPokeEV ) );

	new PM_POKESTAT:iStatNum = POKESTAT_ATTACK_EV;
	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "Attack: %d<br>", StatCalculate( iStatNum, iPokeID, iLevel, g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ iStatNum ], StatSingleIV( iPokeIVs, iStatNum ) ) );
	iStatNum = POKESTAT_DEFENSE_EV;
	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "Defense: %d<br>", StatCalculate( iStatNum, iPokeID, iLevel, g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ iStatNum ], StatSingleIV( iPokeIVs, iStatNum ) ) );
	iStatNum = POKESTAT_SPEED_EV;
	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "Speed: %d<br>", StatCalculate( iStatNum, iPokeID, iLevel, g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ iStatNum ], StatSingleIV( iPokeIVs, iStatNum ) ) );
	iStatNum = POKESTAT_SPECIAL_EV;
	iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "Special: %d<br>", StatCalculate( iStatNum, iPokeID, iLevel, g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ iStatNum ], StatSingleIV( iPokeIVs, iStatNum ) ) );

	iLen += copy( szMOTD[iLen], charsmax(szMOTD)-iLen, "</td></tr></table></td><td>" );

	for ( iPokeNum = 0; iPokeNum < POKEMON_PER_PLAYER; iPokeNum++ )
	{
		iPokeID = g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ POKESTAT_POKEMON ];
		if ( iPokeID <= 0 )
			continue;

		iLen += formatex( szMOTD[iLen], charsmax(szMOTD)-iLen, "%d. <img src=^"%s^"> %s - Level %d<br>", iPokeNum + 1, PokemonInfo( iPokeID, "ImageS" ), PokeNumToName( iPokeNum, .playerID = iOwner ), g_iPlayerPokemonStats[ iOwner ][ iPokeNum ][ POKESTAT_LEVEL ] );
	}

	iLen += copy( szMOTD[iLen], charsmax(szMOTD)-iLen, "</td></tr></table>" );

	show_motd( iViewer, szMOTD, szTitle );

	pokemod_funcend_debug( "PokemonShowInfo" );

	return PLUGIN_HANDLED
}








